<template>
<stUCommentReplyDetail ref="commentReplyDetail"
                       :group-flag="$config.activityGroupFlag"
                       @detailAvatarClick="detailAvatarClick"
                       @detailStarAvatarClick="detailStarAvatarClick"
                       @detailToAllStarClick="detailToAllStarClick"
                       @detailReplyClick="detailReplyClick"
                       @replyAvatarClick="replyAvatarClick"
                       @replyStarAvatarClick="replyStarAvatarClick"
                       @replyToAllStarClick="replyToAllStarClick"
                       @replyReplycommentReplyClick="replyReplycommentReplyClick"
                       @replyReplyCommentHierarchicalAvatarClick="replyReplyCommentHierarchicalAvatarClick"
                       @replyToAllReplyClick="replyToAllReplyClick"

                       @replyReplyClick="replyReplyClick"
                       :comment-subject-id="commentId"></stUCommentReplyDetail>
</template>

<script>
import stUCommentReplyDetail from '../../../../../../../components/comment/web/components/app/uni-app/st-u-comment-subject-detail/st-u-comment-subject-detail.vue'
export default {
  components: {stUCommentReplyDetail},
  data(){
    return {
      // 上一个页面传递的评论id
      commentId: '',
      // 上一个页面传递的活动id
      activityId: ''
    }
  },
  onLoad(options){
    this.commentId = options.commentId
    this.activityId = options.activityId
    // 监听下一个页面发布成功的数据
    // 评论添加完成
    uni.$on('activity_commentHierarchicalForCommentPublishSuccess',this.commentHierarchicalForCommentPublishSuccess)
    // 评论的评论，即回复的回复发布成功数据处理
    uni.$on('activity_commentHierarchicalForCommentHierarchicalPublishSuccess',this.commentHierarchicalForCommentHierarchicalPublishSuccess)
  },
  onUnload() {
    uni.$off('activity_commentHierarchicalForCommentPublishSuccess',this.commentHierarchicalForCommentPublishSuccess);
    uni.$off('activity_commentHierarchicalForCommentHierarchicalPublishSuccess',this.commentHierarchicalForCommentHierarchicalPublishSuccess);
  },
  // 下拉刷新
  onPullDownRefresh(){
    // 这里下拉刷新只刷新列表，不刷新评论详细信息，感觉没有必要
    this.$refs.commentReplyDetail.refreshCommentHierarchicalForSubject(()=>{uni.stopPullDownRefresh()})
  },
  onReachBottom(){
    this.$refs.commentReplyDetail.loadCommentHierarchicalForSubject()
  },
  methods: {
    // 监听事件处理方法，因为这个页面可能是从活动直接点击过来的
    commentHierarchicalForCommentPublishSuccess(comment){
      if (this.$refs.commentReplyDetail) {
        this.$refs.commentReplyDetail.replyPrependCommentHierarchical(comment)
        // 发送到上一个页面（活动页面，如果不是从活动页面进来的，activityId应该为空），修改回复数 加1
        if(this.activityId){
          uni.$emit('activity_commentItemReplyCountIncrement',{comment: comment,activityId: this.activityId})
        }
      }
    },
    // 回复和回复发布成功处理，这里直接添加在页面上，不对后台处理
    commentHierarchicalForCommentHierarchicalPublishSuccess(commentHierarchical){
      if (this.$refs.commentReplyDetail) {
        this.$refs.commentReplyDetail.replyReplyPrependCommentHierarchical(commentHierarchical)
      }
    },
    // 点击详情用户头像，跳转到用户详情
    detailAvatarClick(commentSubject){
      this.navigateToUserDetail(commentSubject.ownerUserId)
    },
    // 点击详情点赞头像，跳转到用户详情
    detailStarAvatarClick({starItem}){
      this.navigateToUserDetail(starItem.ownerUserId)
    },
    // 点击详情更多点赞，跳转到点赞列表
    detailToAllStarClick(commentSubject){
      uni.navigateTo({
        url: '/pages/activity/activityCommentStar?commentSubjectId=' + commentSubject.id
      })
    },
    // 点击详情回复，跳转到回复页
    detailReplyClick(commentSubject){
      this.checkLogin().then(()=>{
        let q = {
          targetUserId: commentSubject.ownerUserId,
          subjectId: commentSubject.id
        }
        uni.navigateTo({
          url: '/pages/activity/activityCommentHierarchicalForCommentPublish' + this.$u.queryParams(q)
        })
      })
    },
    // 点击回复人的头像跳转到用户详情页
    replyAvatarClick(commentHierarchical){
      this.navigateToUserDetail(commentHierarchical.ownerUserId)
    },
    // 点击回复的点赞人头像，跳转到用户详情页
    replyStarAvatarClick({subCommentHierarchical}){
      this.navigateToUserDetail(subCommentHierarchical.ownerUserId)
    },
    // 回复的全部点赞列表
    replyToAllStarClick(commentHierarchical){
      uni.navigateTo({
        url: '/pages/activity/activityCommentHierarchicalStar?commentHierarchicalId=' + commentHierarchical.id
      })
    },
    // 点击回复的回复人头像，跳转到用户详情页
    replyReplyCommentHierarchicalAvatarClick({subCommentHierarchical}){
      this.navigateToUserDetail(subCommentHierarchical.ownerUserId)
    },
    // 回复的回复点击，跳转到层级谁详情
    replyReplycommentReplyClick({subCommentHierarchical}){
      uni.navigateTo({
        url: '/pages/activity/activityCommentHierarchicalReplyDetail?commentHierarchicalId=' + subCommentHierarchical.id
      })
    },
    // 回复的下级回复全部点击事件，跳转到回复的详情
    replyToAllReplyClick(commentHierarchical){
      uni.navigateTo({
        url: '/pages/activity/activityCommentHierarchicalReplyDetail?commentHierarchicalId=' + commentHierarchical.id
      })
    },
    // 对回复进行回复
    replyReplyClick(commentHierarchical){
      let q = {
        commentHierarchicalId: commentHierarchical.id,
        targetUserId: commentHierarchical.ownerUserId
      }
      // 为了方便传参，这里使用 uview封装的路由跳转
      this.$u.route({
        url: '/pages/activity/activityCommentHierarchicalForHierarchicalPublish',
        params: q
      })
    },
    // 跳转到用户详情
    navigateToUserDetail(userId){
      uni.navigateTo({
        url: '/pages/index/userDetail?userId=' + userId
      })
    },
  }
}
</script>

<style scoped>

</style>